//
//  JZDynamicTableViewCell.m
//  QuanZiChat
//
//  Created by 张洪林 on 15/11/28.
//  Copyright © 2015年 ZhongHongLin. All rights reserved.
//

#import "JZDynamicTableViewCell.h"
#import "JZDynamicRichTextView.h"
@interface JZDynamicTableViewCell ()<JZDynamicRichTextViewDelegate>
@property (nonatomic,strong) JZDynamicRichTextView* dynamicRichTextView;
@end
@implementation JZDynamicTableViewCell
+(CGFloat)calculateCellHeightWithAlbum:(JZAlbum*)album{
    return [JZDynamicRichTextView calculateRichTextHeightWithAlbum:album];
}



-(JZDynamicRichTextView*)albumRichTextView{
    if(_dynamicRichTextView==nil){
        _dynamicRichTextView=[[JZDynamicRichTextView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([[UIScreen mainScreen] bounds]), 40)];
        _dynamicRichTextView.richTextViewDelegate=self;
    }
    return _dynamicRichTextView;
}

-(void)setCurrentAlbum:(JZAlbum *)currentAlbum{
    _currentAlbum=currentAlbum;
    _dynamicRichTextView.album=currentAlbum;
}

-(void)setup{
    self.selectionStyle=UITableViewCellSelectionStyleNone;
    [self.contentView addSubview:self.albumRichTextView];
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setup];
    }
    return self;
}

-(void)dealloc{
    _dynamicRichTextView=nil;
}

-(void)didCommentButtonClick:(UIButton *)button{
    if([_dynamicTableViewCellDelegate respondsToSelector:@selector(didCommentButtonClick:indexPath:)]){
        [_dynamicTableViewCellDelegate didCommentButtonClick:button indexPath:self.indexPath];
    }
}

-(void)didSelectCommentAtIndexPath:(NSIndexPath *)indexPath{
    if([_dynamicTableViewCellDelegate respondsToSelector:@selector(didSelectCommentAtCellIndexPath:commentIndexPath:)]){
        [_dynamicTableViewCellDelegate didSelectCommentAtCellIndexPath:self.indexPath commentIndexPath:indexPath];
    }
}

- (void)prepareForReuse {
    [super prepareForReuse];
    self.albumRichTextView.album = nil;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
